--
-- Author: mm
-- Date: 2018-03-24 17:23:05
--
-- NewguildIconRender 对应 base_guild_icon.csb
-- 公会头像render

local ClassRef = app.mvc.createRenderClass(...)

--data =
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.NewGuildIconNode))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
    self.super.init(self, data)

    self:setContentSize(self._ui.Panel_icon:getContentSize())

    display.uiAddClick(self._ui.Panel_icon, function()
        executeFunc(self._onClick, self)
    end)

    self:refresh()
end

-- data = NewguildInfo:getGuildIcon()
-- local param = {
--     baseIconId = self._gFlagBaseIconID,
--     baseIconColor = self._gFlagColorId,
--     additionIconId = self._gFlagAdditionalIconId,
--     additionIconColor = self._gFlagColorId
-- }
function ClassRef:refresh()
    if self._data then
        local data = self._data

        if data.baseIconId then
            local baseIconPath = GD:getImagePath( Res.guildIconPath, data.baseIconId )
            --dump(baseIconPath)
            self._ui.icon_u:loadTexture( baseIconPath )
        end

        if data.additionIconId then
            local additionalIconPath = GD:getImagePath( Res.guildIconPath, data.additionIconId )
            self._ui.icon_b:loadTexture( additionalIconPath )
        end

        if data.baseIconColor then
            self._ui.icon_u:setColor( app:getInst("NewguildModel"):getBaseIconColorList()[ data.baseIconColor ] )
        end

        if data.additionIconColor then
            self._ui.icon_b:setColor( app:getInst("NewguildModel"):getAdditionalIconColorList()[ data.additionIconColor ] )
        end
        self:setVisible(true)
    end
end

function ClassRef:setBaseIcon( baseIconPath )
    if not baseIconPath or "" == baseIconPath then return end

    local iconPath = GD:getImagePath( Res.guildIconPath, baseIconPath )
    self._ui.icon_u:loadTexture( iconPath )
end
function ClassRef:setBaseIconColor( baseColor )
    if not baseColor then return end
    self._ui.icon_u:setColor( baseColor )
end

function ClassRef:setAdditionalIcon( additionalIconPath )
    if not additionalIconPath or "" == additionalIconPath then return end

    local iconPath = GD:getImagePath( Res.guildIconPath, additionalIconPath )
    self._ui.icon_b:loadTexture( iconPath )
end
function ClassRef:setAdditionalIconColor( additionalColor )
    if not additionalColor then return end
    self._ui.icon_b:setColor( additionalColor )
end

function ClassRef:onBtnClick(cb)
    self._onClick = cb
end

return ClassRef
